package com.hefu.virtuallife.ui.ticket;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.fei.root.common.Display;
import com.fei.root.recater.adapter.CommonAdapter;
import com.fei.root.recater.decoration.DividerDecoration;
import com.fei.root.recater.viewholder.CommonHolder;
import com.hefu.virtuallife.R;
import com.hefu.virtuallife.base.BaseFragment;
import com.hefu.virtuallife.bean.TrainTicketBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by pc on 2018/8/7.
 */

public class TicketInfoListFragment extends BaseFragment {
    @BindView(R.id.rv_ticketlist)
    RecyclerView rv_ticketlist;

    CommonAdapter<TrainTicketBean> mAdapter;
    private List<TrainTicketBean> mData = new ArrayList<TrainTicketBean>();

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_ticket_info_list;
    }

    @Override
    protected void init(Bundle savedInstanceState, View view) {
        mAdapter=new CommonAdapter<TrainTicketBean>(mData,R.layout.layout_item_ticket) {
            @Override
            protected void convert(CommonHolder holder, TrainTicketBean trainTicketBean, int position) {
                TextView tv_numer = holder.getTextView(R.id.tv_number);
                tv_numer.setText(trainTicketBean.getNumber());

                TextView tv_startTime = holder.getTextView(R.id.tv_starttime);
                tv_startTime.setText(trainTicketBean.getStartTime());

                TextView tv_spentTime = holder.getTextView(R.id.tv_spenttime);
                tv_spentTime.setText(trainTicketBean.getSpendTime());

                TextView tv_arriveTime = holder.getTextView(R.id.tv_arrivetime);
                tv_arriveTime.setText(trainTicketBean.getArriveTime());

                TextView tv_info1 = holder.getTextView(R.id.tv_info1);
                tv_info1.setText(trainTicketBean.getTicketInfo1());

                TextView tv_info2 = holder.getTextView(R.id.tv_info2);
                tv_info2.setText(trainTicketBean.getTicketInfo2());

                TextView tv_info3 = holder.getTextView(R.id.tv_info3);
                tv_info3.setText(trainTicketBean.getTicketInfo3());

                TextView tv_from = holder.getTextView(R.id.tv_from);
                tv_from.setText(trainTicketBean.getFrom());

                TextView tv_to = holder.getTextView(R.id.tv_to);
                tv_to.setText(trainTicketBean.getTo());
            }

        };

        rv_ticketlist.setLayoutManager(new LinearLayoutManager(getBaseActivity()));
        rv_ticketlist.addItemDecoration(new DividerDecoration(ContextCompat.getColor(getBaseActivity(), R.color.transparent), (int) Display.dp2px(1)));
        rv_ticketlist.setAdapter(mAdapter);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public static TicketInfoListFragment newInstance(String content) {
        TicketInfoListFragment fragment = new TicketInfoListFragment();
        Bundle bundle = new Bundle();
        bundle.putString("data", content);
        fragment.setArguments(bundle);
        return fragment;
    }

    public void initData(List<TrainTicketBean> data) {
        mData = data;
    }

    public void addData(List<TrainTicketBean> data) {
        mData = data;
        mAdapter.appendItems(data);
    }
}
